import { number } from "@hapi/joi";
import mongoose, { Document, Schema } from "mongoose";

interface IUser extends Document {
  password: string;
  account: string;
}

interface INotes extends Document {
  pid: string;
  personal: {
    name: string;
    phone: string;
    img: string;
  };
}

const UserSchema: Schema = new Schema({
  password: { type: String, required: true },
  account: {
    type: String,
    required: true,
    unique: true,
  },
  roles: { type: Array, default: [0] },
  avatarUrl: { type: String, default: "" },
  note: [{ type: mongoose.Schema.Types.ObjectId, ref: "notes" }],
});

const RoleSchema: Schema = new Schema({
  name: { type: String, required: true },
  route: [{ type: Schema.Types.ObjectId, ref: "route" }],
});

const RouteSchema: Schema = new Schema({
  path: { type: String, required: true },
  name: { type: String, required: true },
  parentId: { type: String, required: false, default: 0 },
});

// const Permission: Schema = new Schema({
//   name: {
//     type: Number,
//   },
//   roles: [],
// });
//用户表 建立连接 角色表  角色表和权限表建立连接
//权限表如何设计？
//

const NotesSchema: Schema = new Schema({
  pid: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "user",
  },
  noteName: mongoose.Schema.Types.String,
  personal: mongoose.Schema.Types.Mixed, //个人资料
  selfEvaluation: mongoose.Schema.Types.Mixed, //自我评价
  educationalBg: mongoose.Schema.Types.Mixed, //教育背景
  workExperience: mongoose.Schema.Types.Mixed, //工作经历
  certificate: mongoose.Schema.Types.Mixed, //证书
  skills: mongoose.Schema.Types.Mixed, //技能
  hobby: mongoose.Schema.Types.Mixed, //兴趣爱好
  isVertical: {
    type: mongoose.Schema.Types.Boolean,
    default: false,
  },
  status: {
    type: mongoose.Schema.Types.Boolean,
    default: false,
  },
  type: { type: String, default: "0" },
});

const resumeTypeSchema = new mongoose.Schema({
  type: {
    type: String,
    required: true,
  },
  typeImage: {
    type: String,
    required: true,
  },
  typeTitle: {
    type: String,
    required: true,
  },
});

const tempalteCate = new mongoose.Schema({
  cateTitle: {
    type: String,
    required: true,
  },
  temList: [{ type: mongoose.Schema.Types.ObjectId, ref: "templates" }],
});

const templates = new mongoose.Schema({
  temImage: {
    type: String,
    required: true,
  },
  temTitle: {
    type: String,
    required: true,
  },
  details: [{ type: mongoose.Schema.Types.ObjectId, ref: "temDetails" }],
});

const tmpNoteDetails = new Schema({
  noteName: mongoose.Schema.Types.String,
  personal: mongoose.Schema.Types.Mixed, //个人资料
  selfEvaluation: mongoose.Schema.Types.Mixed, //自我评价
  educationalBg: mongoose.Schema.Types.Mixed, //教育背景
  workExperience: mongoose.Schema.Types.Mixed, //工作经历
  certificate: mongoose.Schema.Types.Mixed, //证书
  skills: mongoose.Schema.Types.Mixed, //技能
  hobby: mongoose.Schema.Types.Mixed, //兴趣爱好
  isVertical: {
    type: mongoose.Schema.Types.Boolean,
    default: false,
  },
  type: { type: String, default: 0 },
});

//用户
export const User = mongoose.model<IUser>("user", UserSchema);
//简历
export const Notes = mongoose.model<INotes>("notes", NotesSchema);
//简历样式类型
export const NoteCate = mongoose.model("notecate", resumeTypeSchema);
//简历分类
export const TempalteCate = mongoose.model("tempalteCate", tempalteCate);
//简历模板集合
export const TempalteList = mongoose.model("templates", templates);
//模板简历具体详情
export const TemCateDetails = mongoose.model("temDetails", tmpNoteDetails);
//角色
export const roles = mongoose.model("role", RoleSchema);
//路由
export const Routes = mongoose.model("route", RouteSchema);
